home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / dtr / editlist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  31.3 KB  |  903 lines

  1. /*
  2.  * Copyright (c) 1990, 1991, 1992 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /*$Header: /Source/Media/collab/DTR/RCS/editlist.c,v 1.15 93/02/11 21:00:35 drapeau Exp $*/
  25. /* $Log:    editlist.c,v $
  26.  * Revision 1.15  93/02/11  21:00:35  drapeau
  27.  * Fixed errors in calls to xv_set(); they were not NULL-terminated.
  28.  * Also, made minor cosmetic changes to the code for improved readability.
  29.  * 
  30.  * Revision 1.14  92/05/29  12:42:13  drapeau
  31.  * Modified code to track new name of the MAEstro "Selection" structure;
  32.  * it is now named "MAESelection".
  33.  * 
  34.  * Revision 1.13  92/03/02  16:08:12  drapeau
  35.  * Modified SetCurrentSelection() -- previous changes to accommodate
  36.  * partial selections introduced rounding errors.  This change corrects
  37.  * the rounding errors, which would cut off as much as a second from
  38.  * the end of an edit's audio.
  39.  * 
  40.  * Revision 1.12  92/03/02  12:30:01  drapeau
  41.  * Modified SetCurrentSelection() to handle requests from the network
  42.  * for partial selections.  This function now takes into account
  43.  * both the duration and offset fields of a Selection* structure
  44.  * passed into the function as argument; if the duration differs
  45.  * from the default selection, the requested duration will be set
  46.  * (if possible).  If the offset is non-zero, this function will
  47.  * attempt to accommodate the new offset value.
  48.  * 
  49.  * Revision 1.11  92/01/07  14:26:59  drapeau
  50.  * * Modified SetEditList() to clean up the updating of current
  51.  *   edit list name.
  52.  * * Modified FormatEntry() to reflect new interface.  The current
  53.  *   sound file for the current edit is no longer displayed directly on
  54.  *   the scrolled list since it is shown in several other places.
  55.  * * Modified SetCurrentSelection() to clean up the semantics and make
  56.  *   more robust.  The function now allows for previewing of selections
  57.  *   before they are added to the edit list, and also allows for direct
  58.  *   loading of selection simply by dragging the mouse over the desired
  59.  *   area on the Wave Canvas.  Before this modification, a button labeled
  60.  *   "Load Selection" needed to be pressed before the selection was loaded.
  61.  * * Simplified NewEditList() so that it simply clears out the current
  62.  *   edit list and begins anew.  The author is no longer required to pick
  63.  *   a filename for the new, empty edit list.
  64.  * Also, Made a number of cosmetic changes to make code easier to read and
  65.  * to conform to programming specifications.
  66.  * 
  67.  * Revision 1.10  91/09/18  22:47:23  derek
  68.  * The following things are done:
  69.  * 1.    The Makefile is changed corresponding to the changes in collab/.
  70.  * 2.    Copyright messages included.
  71.  * 3.    Some minor bugs fixed.
  72.  * 
  73.  * Revision 1.9  91/08/22  15:47:06  derek
  74.  * The format of the DTR edit-list has been changed.  The header is 
  75.  * changed from "#DTR Edit File#" to "#DTR Edit Document#".  Also,
  76.  * EditNumber is added to every edit within the edit-list.
  77.  * 
  78.  * Revision 1.8  91/08/21  11:34:16  derek
  79.  * The following changes are made:
  80.  * 1.    Now the duration and size of the recorded sound will be displayed
  81.  *     during recording.
  82.  * 2.    I have changed GetSelection() corresponding to the request of Tek joo
  83.  * 3.    Info Panel is added to the application.
  84.  * 4.    Fixed SizeToFitHandler() so that when no file or buffer is currently
  85.  *     loaded, it would not do anything (except giving a warning
  86.  *     notice_prompt).
  87.  * 5.    Inplemented the `Close' Menu option in the document menu.
  88.  * 6.    Fixed the bug in which after ClearAll and I press PreviewEdit,
  89.  *     the edit wont be played.
  90.  * 7.    I have made the changes corresponding to the change in OpenPanel's
  91.  *     name.  (from OpenPanel to Browse).
  92.  * 8.    Incorporated BrowseCheck to check command line arg.
  93.  * 9.    Changed most EditingStatusMessages to NoticePrompts.
  94.  * 10.    SoundFileSaveAsPopUp and EditListSaveAsPopUp are removed 
  95.  *     from the application.
  96.  * 
  97.  * Revision 1.7  91/08/16  18:10:37  derek
  98.  * 
  99.  * The following things are done:
  100.  * 1.    I have fixed an openpanel bug in my code in which I 
  101.  *     made the app return the wrong values to OpenHandler and
  102.  *     the SaveHandler.
  103.  * 2.    The flashing color of the play button has been changed from
  104.  *     Red to Green.
  105.  * 3.    Fixed a quantization bug: Buffer.play.end, when converted
  106.  *     from endingTimeInSec, should not exceed Buffer_hdr_data_size - 1.
  107.  * 
  108.  * Revision 1.6  91/08/14  18:16:51  derek
  109.  * The following things are done:
  110.  * 1.    I changed the name of the "save as" and "save" menu options
  111.  *     to be more specific.  ie. to "save sound file" and "save edit list".
  112.  * 2.    I removed the preview panel popup and replaced it with a preview
  113.  *     edit button.
  114.  * 3.    I changed the message displayed by UpdateSpaceOnTmp() to consist
  115.  *     only of the time remaining and the amount of space left.  There is
  116.  *     no more percentage indicating the capacity of /usr/tmp.
  117.  * 
  118.  * Revision 1.5  91/08/08  21:44:35  derek
  119.  * Fixed a number of bugs.
  120.  * 
  121.  * Revision 1.4  91/08/08  11:27:54  derek
  122.  * I have fixed a minor bug.
  123.  * 
  124.  * Revision 1.3  91/08/08  11:02:10  derek
  125.  * This is a cleaner version.  I have removed lots of printf/fprintf 
  126.  * statements from it, and have also cleaned up the code using xsaber.
  127.  * This version should run substantially faster.
  128.  * 
  129.  * Revision 1.2  91/08/07  16:24:13  derek
  130.  * The Edit list part of DTR is done.  OpenPanel is also incorporated.
  131.  * 
  132.  * Revision 1.1  91/08/06  12:41:13  derek
  133.  * Initial revision
  134.  *  */
  135. static char rcsid[] = "$Header: /Source/Media/collab/DTR/RCS/editlist.c,v 1.15 93/02/11 21:00:35 drapeau Exp $";
  136.  
  137. #include "dtr.h"              
  138. #include "dtr_ui.h"
  139.  
  140. extern    dtr_editListPanelPopUp_objects        *dtr_editListPanelPopUp;
  141.  
  142. Xv_font *listFont;
  143.  
  144. void
  145.   InitEditList()
  146. {
  147.   int    i;
  148.   
  149.   EditList.soundFile     = (char   **) malloc(DEFAULT_EDITLIST_SIZE * sizeof(char *));
  150.   EditList.label         = (char   **) malloc(DEFAULT_EDITLIST_SIZE * sizeof(char *));
  151.   for(i = 0; i < DEFAULT_EDITLIST_SIZE ; i++)
  152.   {
  153.     EditList.soundFile[i] = (char *) malloc(80);
  154.     EditList.label[i]     = (char *) malloc(40);
  155.   }
  156.   
  157.   EditList.startingMin   = (int     *) malloc(DEFAULT_EDITLIST_SIZE * sizeof(int));
  158.   EditList.startingSec   = (double  *) malloc(DEFAULT_EDITLIST_SIZE * sizeof(double));
  159.   EditList.endingMin     = (int     *) malloc(DEFAULT_EDITLIST_SIZE * sizeof(int));
  160.   EditList.endingSec     = (double  *) malloc(DEFAULT_EDITLIST_SIZE * sizeof(double));
  161.   EditList.volume        = (int     *) malloc(DEFAULT_EDITLIST_SIZE * sizeof(int));
  162.   EditList.capacity      = DEFAULT_EDITLIST_SIZE;
  163.   EditList.numItems      = 0;
  164.   
  165.   currentSelection = NO_CURRENT_EDIT;
  166.   unsavedChangesExist = FALSE;
  167.   currentSelectionReadyToPlay = FALSE;
  168.   SetScrollListFont();
  169.   sprintf(absoluteEditListName, "Untitled");
  170. }                                    /* end function InitEditList */
  171.   
  172.  
  173. void
  174.   SetScrollListFont()
  175. {
  176.   listFont = (Xv_font *) xv_find(dtr_editListPanelPopUp->editListPanelPopUp, FONT,
  177.                  FONT_FAMILY, FONT_FAMILY_LUCIDA_FIXEDWIDTH,
  178.                  FONT_STYLE, FONT_STYLE_NORMAL,
  179.                  FONT_SIZE, 12,
  180.                  NULL);
  181. }
  182.  
  183.  
  184. /*
  185.  *  This function is called when the current number of edits is close to the
  186.  *  default max allowed number.
  187.  */
  188. void
  189.   ReallocateMemoryForEditList()
  190. {
  191.   int    i;
  192.  
  193.   EditList.soundFile     = (char   **) realloc(EditList.soundFile,
  194.                            (EditList.capacity + DEFAULT_EDITLIST_SIZE) * sizeof(char *));
  195.   EditList.label         = (char   **) realloc(EditList.label,
  196.                            (EditList.capacity + DEFAULT_EDITLIST_SIZE) * sizeof(char *));
  197.   for(i = EditList.capacity ;                        
  198.       i < EditList.capacity + DEFAULT_EDITLIST_SIZE ;
  199.       i++)                        
  200.   {
  201.     EditList.soundFile[i] = (char *) malloc(80);
  202.     EditList.label[i]     = (char *) malloc(40);
  203.   }
  204.  
  205.   EditList.startingMin   = (int     *) realloc(EditList.startingMin,
  206.                            (EditList.capacity + DEFAULT_EDITLIST_SIZE) * sizeof(int));
  207.   EditList.startingSec   = (double  *) realloc(EditList.startingSec,
  208.                            (EditList.capacity + DEFAULT_EDITLIST_SIZE) * sizeof(double));
  209.   EditList.endingMin     = (int     *) realloc(EditList.endingMin,
  210.                            (EditList.capacity + DEFAULT_EDITLIST_SIZE) * sizeof(int));
  211.   EditList.endingSec     = (double  *) realloc(EditList.endingSec,
  212.                            (EditList.capacity + DEFAULT_EDITLIST_SIZE) * sizeof(double));
  213.   EditList.volume        = (int     *) realloc(EditList.volume,
  214.                            (EditList.capacity + DEFAULT_EDITLIST_SIZE) * sizeof(int));
  215.   EditList.capacity += DEFAULT_EDITLIST_SIZE;
  216. }  
  217.  
  218.  
  219. int
  220.   ReadEditListFromFile(fileName, caller)
  221. char   *fileName;
  222. char   caller;
  223. {
  224.   double    duration;
  225.   FILE        *fp;
  226.   int        size;
  227.   int        counter;
  228.   int           garbage;
  229.   
  230.   if (unsavedChangesExist == TRUE)
  231.   {
  232.     int    reply;
  233.       
  234.     sprintf(msg, "Unsaved changes in %s edit list exist, load new edit list anyway?", prog);
  235.     reply = notice_prompt(dtr_editListPanelPopUp->editListUpperControlPanel, NULL,
  236.               NOTICE_MESSAGE_STRINGS,
  237.               msg,
  238.               NULL,
  239.               NOTICE_BUTTON, "Yes", 'Y',
  240.               NOTICE_BUTTON, "No", 'C',
  241.               NULL);
  242.     if (reply == 'C')
  243.       return FILE_NOT_OK;
  244.   }
  245.   
  246.   fp = fopen (fileName, "r");                        /*  Attempt to open the specified file.             */
  247.   if (fp == (FILE*)NULL)                        /*  Did the open succeed?                           */
  248.   {                                    /*  No, inform author and return w/o doing anything */
  249.     sprintf(msg, "'%s'", fileName);
  250.     notice_prompt(dtr_editListPanelPopUp->editListUpperControlPanel,
  251.           NULL,
  252.           NOTICE_MESSAGE_STRINGS,
  253.           "Unable to open editlist",
  254.           msg,
  255.           NULL,
  256.           NOTICE_BUTTON, "OK", 'O',
  257.           NULL);
  258.     return FILE_NOT_OK;
  259.   }
  260.   
  261.   fscanf (fp, "#%s Edit Document#\n", msg);                /*  Is this file a DTR Editlist file?               */
  262.   if (strcmp(msg, "DTR"))                        /*  No, this is not a DTR Editlist file.            */
  263.   {                                    /*  Inform the author of the mistake and return.    */
  264.     if (caller == USER)
  265.     {
  266.       sprintf(msg, "'%s'", fileName);
  267.       notice_prompt(dtr_editListPanelPopUp->editListUpperControlPanel,
  268.             NULL,
  269.             NOTICE_MESSAGE_STRINGS,
  270.             msg,
  271.             "is not a valid DTR edit list",
  272.             NULL,
  273.             NOTICE_BUTTON, "OK", 'O',
  274.             NULL);
  275.     }
  276.     return FILE_NOT_OK;                            /*  Exit regardless if called from network or by... */
  277.                                     /*  ...the author.                                  */
  278.   }
  279.   DeselectList();
  280.   ResetCurrentSelection();
  281.   EmptyList();
  282.   fscanf (fp, "#Number of Edits:\t%d", &size);                /*  Read the size of the edit list to be read in.   */
  283.   EditList.numItems = size;
  284.   if (size > EditList.capacity - 2)
  285.   {
  286.     for(counter = 1 ; counter < ((size+2)/DEFAULT_EDITLIST_SIZE)+1; /*  If not enough memory in edit list data...       */
  287.     counter++)                            /*  ...structure, reallocate data repeatedly.       */
  288.       ReallocateMemoryForEditList();
  289.   }
  290.   
  291.   for (counter = 0; counter < size; counter ++)                /* Read through the edit list file, loading it... */
  292.   {                                    /* ...into the edit list, entry by entry. */
  293.     fscanf(fp, "\n#EditNumber:\t%d\n#SoundFile:\t%s\n#StartingMin:\t%d\n#StartingSec:\t%lf\n#EndingMin:\t%d\n#EndingSec:\t%lf\n#Volume:\t%d\n#Label:\t", 
  294.        &garbage,
  295.        EditList.soundFile[counter],
  296.        &EditList.startingMin[counter],
  297.        &EditList.startingSec[counter],
  298.        &EditList.endingMin[counter],
  299.        &EditList.endingSec[counter],
  300.        &EditList.volume[counter]);
  301.     fgets(EditList.label[counter], 40, fp);
  302.     duration = (EditList.endingMin[counter] - EditList.startingMin[counter]) * 60.0 
  303.       + EditList.endingSec[counter] - EditList.startingSec[counter];
  304.     
  305.     xv_set (dtr_editListPanelPopUp->editListScrollList,
  306.         PANEL_LIST_INSERT, counter,
  307.         PANEL_LIST_STRING, counter,
  308.         FormatEntry(counter+1,
  309.             EditList.label[counter],
  310.             EditList.soundFile[counter],
  311.             duration),
  312.         PANEL_LIST_FONT, counter, listFont,
  313.         NULL);
  314.   }
  315.   fclose(fp);
  316.   UpdateNumEditsMessage();
  317.   SetEditList(fileName);
  318.   unsavedChangesExist = FALSE;
  319.   return FILE_OK;
  320. }                                    /* end function ReadEditListFromFile */
  321.  
  322.  
  323.  
  324. void
  325.   DeselectList()
  326. {
  327.   if (currentSelection != NO_CURRENT_EDIT)
  328.   {
  329.     xv_set (dtr_editListPanelPopUp->editListScrollList,
  330.         PANEL_LIST_SELECT, currentSelection, FALSE,
  331.         NULL);
  332.     currentSelection = NO_CURRENT_EDIT;
  333.   }
  334.   xv_set(dtr_editListPanelPopUp->currentEditMessage,
  335.      PANEL_LABEL_STRING, "New Edit",
  336.      NULL);
  337.   xv_set(dtr_editListPanelPopUp->deleteButton,
  338.      PANEL_INACTIVE, TRUE, NULL);                    /* De-activate the Delete and Modify buttons */
  339.   xv_set(dtr_editListPanelPopUp->modifyButton,
  340.      PANEL_INACTIVE, TRUE, NULL);
  341. }
  342.  
  343.  
  344. int
  345.   WriteEditListToFile(fileName)
  346. char    *fileName;
  347. {
  348.   int    size;
  349.   int    counter;
  350.   FILE    *fp;
  351.  
  352.   size = EditList.numItems;
  353.   
  354.   DeselectList();
  355.   fp = fopen (fileName, "w");                        /*  Attempt to open the edit list passed in for...  */
  356.                                     /*  ...writing.                                     */
  357.   if (fp == (FILE*)NULL)                        /*  Did the open fail?                              */
  358.   {                                    /*  Yes, unable to open the file for writing. ...   */
  359.     sprintf(msg, "'%s'", fileName);
  360.     notice_prompt(dtr_editListPanelPopUp->editListUpperControlPanel,
  361.           NULL,
  362.           NOTICE_MESSAGE_STRINGS,
  363.           msg,
  364.           "is a bad/non-writable file name.",
  365.           NULL,
  366.           NOTICE_BUTTON, "OK", 'O',
  367.           NULL);
  368.     return FILE_NOT_OK;
  369.   }
  370.   fprintf (fp, "#DTR Edit Document#\n");                /*  Write the file header determining the type...   */
  371.                                     /*  ... of this file.                               */
  372.   size = EditList.numItems;
  373.   fprintf (fp, "#Number of Edits:\t%d\n\n", size);            /*  Write number of edits made for this document.   */
  374.   for (counter = 0; counter < size; counter ++)                /*  Loop through each item in the edit list, ...    */
  375.   {                                    /*  ...writing contents of each item to the file.   */
  376.     fprintf(fp, "#EditNumber:\t%d\n#SoundFile:\t%s\n#StartingMin:\t%d\n#StartingSec:\t%lf\n#EndingMin:\t%d\n#EndingSec:\t%lf\n#Volume:\t%d\n#Label:\t%s\n\n", 
  377.         counter + 1,
  378.         EditList.soundFile[counter],
  379.         EditList.startingMin[counter],
  380.         EditList.startingSec[counter],
  381.         EditList.endingMin[counter],
  382.         EditList.endingSec[counter],
  383.         EditList.volume[counter],
  384.         EditList.label[counter]);
  385.   }
  386.   fclose (fp);                                /* Close the file just written */
  387.   unsavedChangesExist = FALSE;
  388.   SetEditList(fileName);
  389.   return FILE_OK;
  390. }                                    /* end function WriteEditListToFile */
  391.  
  392.   
  393. void
  394.   ResetCurrentSelection()
  395. {
  396.   xv_set(dtr_editListPanelPopUp->soundFileTextField,
  397.      PANEL_VALUE, "", NULL);
  398.   xv_set(dtr_editListPanelPopUp->labelTextField,
  399.      PANEL_VALUE, "", NULL);
  400.   xv_set(dtr_editListPanelPopUp->startingTimeMinuteTextField,
  401.      PANEL_VALUE, "0", NULL);
  402.   xv_set(dtr_editListPanelPopUp->startingTimeSecondTextField,
  403.      PANEL_VALUE, "0.0", NULL);
  404.   xv_set(dtr_editListPanelPopUp->endingTimeMinuteTextField,
  405.      PANEL_VALUE, "0", NULL);
  406.   xv_set(dtr_editListPanelPopUp->endingTimeSecondTextField,
  407.      PANEL_VALUE, "0.0", NULL);
  408.   xv_set(dtr_editListPanelPopUp->currentEditMessage,
  409.      PANEL_VALUE, "New Edit", NULL);
  410. }
  411.  
  412.   
  413. void
  414.   EmptyList()
  415. {
  416.   int    counter;
  417.  
  418.   for(counter = EditList.numItems-1 ; counter > -1; counter--)
  419.   {
  420.     xv_set(dtr_editListPanelPopUp->editListScrollList,
  421.        PANEL_LIST_DELETE, counter,
  422.        NULL);
  423.   }
  424.   EditList.numItems = 0;
  425. }
  426.  
  427.  
  428. void
  429.   UpdateNumEditsMessage()
  430. {
  431.   sprintf(msg, "%d", EditList.numItems);
  432.   xv_set(dtr_editListPanelPopUp->totalNumberOfEditsMessage,
  433.      PANEL_LABEL_STRING, msg, NULL);
  434. }
  435.  
  436.  
  437.      
  438. char  *
  439.   FormatEntry(entryNum, label, fileName, duration)
  440. int    entryNum;
  441. char    *label;
  442. char    *fileName;
  443. double    duration;
  444. {
  445.   int        mins;
  446.   double    secs;
  447.   static char    formattedEntry[100];
  448.  
  449.   mins = irint(floor(duration/60.0));
  450.   secs = duration - mins * 60.0;
  451.   sprintf(msg, "%d:%.1lf", mins, secs);
  452.   sprintf(formattedEntry, "%4d.   %-35.35s  %s", entryNum, label, msg);
  453.   return(formattedEntry);
  454. }
  455.  
  456.  
  457. void SetEditList(char* editListName)
  458. {
  459.   if (strcmp(editListName, "NoneSpecified") != 0)
  460.   {
  461.     sprintf(absoluteEditListName, "%s", editListName);
  462.     UpdateEditListHeader(FALSE);
  463.     realpath(editListName, absoluteEditListName);
  464.   }
  465.   else
  466.   {
  467.     strcpy(absoluteEditListName, "NoneSpecified");
  468.   }
  469.   return;
  470. }                                    /* end function SetEditList */
  471.  
  472.  
  473. void SetCurrentSelection(int entry, MAESelection* selection)
  474. {
  475.   double                    startingTimeInSec;
  476.   double                    endingTimeInSec;
  477.   double                    tempSeconds;
  478.   double                    duration;
  479.   int                        tempMinutes;
  480.   extern dtr_editListPanelPopUp_objects*    dtr_editListPanelPopUp;
  481.   extern dtr_mainWindow_objects*        dtr_mainWindow;
  482.   
  483.   if (entry != NO_CURRENT_EDIT)                        /*  If there is a current Edit, load selection...   */
  484.   {                                    /*  ...parameters from edit list.                   */
  485.     sprintf(msg, "%d", entry + 1);                    /*  Display information on the Edit list panel.     */
  486.     xv_set(dtr_editListPanelPopUp->currentEditMessage,
  487.        PANEL_LABEL_STRING, msg, NULL);
  488.     
  489.     xv_set(dtr_editListPanelPopUp->soundFileTextField,            /*  Set SoundFile text field.                       */
  490.        PANEL_VALUE, EditList.soundFile[entry], NULL);
  491.     xv_set(dtr_editListPanelPopUp->labelTextField,
  492.        PANEL_VALUE, EditList.label[entry], NULL);
  493.     
  494.     sprintf(msg, "%d", EditList.startingMin[entry]);            /*  Set Starting time (minute) text field.          */
  495.     xv_set(dtr_editListPanelPopUp->startingTimeMinuteTextField,
  496.        PANEL_VALUE, msg, NULL);
  497.     
  498.     sprintf(msg, "%.2lf", EditList.startingSec[entry]);            /*  Set starting time (second) text field.          */
  499.     xv_set(dtr_editListPanelPopUp->startingTimeSecondTextField,
  500.        PANEL_VALUE, msg, NULL);
  501.     
  502.     sprintf(msg, "%d", EditList.endingMin[entry]);            /*  Set ending time (minute) text field.            */
  503.     xv_set(dtr_editListPanelPopUp->endingTimeMinuteTextField,
  504.        PANEL_VALUE, msg, NULL);
  505.     
  506.     sprintf(msg, "%.2lf", EditList.endingSec[entry]);            /*  Set ending time (second) text field.            */
  507.     xv_set(dtr_editListPanelPopUp->endingTimeSecondTextField,
  508.        PANEL_VALUE, msg, NULL);
  509.     
  510.     xv_set(dtr_editListPanelPopUp->editListVolumeSlider,        /*  Set volume slider.                              */
  511.        PANEL_VALUE, EditList.volume[entry], NULL);
  512.     xv_set(dtr_mainWindow->playGain,
  513.        PANEL_VALUE, EditList.volume[entry], NULL);
  514.     
  515.     SetPlayGain(EditList.volume[entry]);                /*  Set the play volume of the workstation.         */
  516.     startingTimeInSec = EditList.startingMin[entry] * 60.0        /*  now setting the buffer stuff.                   */
  517.       + EditList.startingSec[entry];
  518.     endingTimeInSec = EditList.endingMin[entry] * 60.0
  519.       + EditList.endingSec[entry];
  520.     sprintf(currentSoundFile, "%s", EditList.soundFile[entry]);
  521.   }                                    /* end if (entry != NO_CURRENT_EDIT)                */
  522.   else                                    /* No current edit, get current selection values... */
  523.   {                                    /* ...from text fields instead of from edit list.   */
  524.     tempMinutes = atoi(xv_get(dtr_editListPanelPopUp->startingTimeMinuteTextField,
  525.                   PANEL_VALUE));
  526.     tempSeconds = atof(xv_get(dtr_editListPanelPopUp->startingTimeSecondTextField,
  527.                   PANEL_VALUE));
  528.     startingTimeInSec = (tempMinutes * 60.0 + tempSeconds);
  529.     
  530.     tempMinutes = atoi(xv_get(dtr_editListPanelPopUp->endingTimeMinuteTextField,
  531.                   PANEL_VALUE));
  532.     tempSeconds = atof(xv_get(dtr_editListPanelPopUp->endingTimeSecondTextField,
  533.                   PANEL_VALUE));
  534.     endingTimeInSec = (tempMinutes * 60.0 + tempSeconds);
  535.   }
  536.   SoundBufferReady = ReadSoundFile(TRUE);                /* Used to read into file, not buffer */
  537.   UpdateHeader(FALSE);
  538.   
  539. /*
  540.   FileReady = ReadSoundFile(FALSE);
  541.   SoundBufferReady = FALSE;
  542. */
  543.   if (selection != (MAESelection*)NULL)                    /* Was this called from SetSelection()? */
  544.   {                                    /* Yes, take into account possible partial selection */
  545.     duration = endingTimeInSec - startingTimeInSec;
  546.     startingTimeInSec += (selection->offset / 1000.0);            /* Account for non-zero offset */
  547.     if (startingTimeInSec < 0)
  548.       startingTimeInSec = 0;
  549.   }
  550.   Buffer.play.start = irint(startingTimeInSec
  551.                 * DEVICE_SAMPLE_RATE);
  552.   if (selection != (MAESelection*)NULL)                    /* Was this called from SetSelection()? */
  553.   {                                    /* Yes, take into account possible partial selection */
  554.     endingTimeInSec += (selection->duration / 1000.0) - duration;   /* Account for duration other than default value */
  555.     if (endingTimeInSec < 0)
  556.       endingTimeInSec = 0;
  557.   }
  558.   Buffer.play.end   = irint(endingTimeInSec
  559.                 * DEVICE_SAMPLE_RATE); 
  560.   if (Buffer.play.end >= Buffer.hdr.data_size)                /*  This makes sure that the round-off error...     */
  561.   {                                    /*  ...caused by the conversion from time to byte.. */
  562.     Buffer.play.end = Buffer.hdr.data_size - 1;                /*  ...wont cause any trouble.                      */
  563.   }
  564.   oldLeftFloatMarker = (double) Buffer.play.start;
  565.   oldRightFloatMarker = (double) Buffer.play.end;
  566.   leftButtonHoldPoint = 0;
  567.   WaveCanvasRightMarkerSet = TRUE;
  568.   
  569.   oldLeftFloatGbWaveMarker = (double) Buffer.play.start;
  570.   oldRightFloatGbWaveMarker = (double) Buffer.play.end;
  571.   GbWaveLeftButtonHoldPoint = 0;
  572.   GlobalWaveCanvasRightMarkerSet = TRUE;
  573.  
  574.   SameSoundFile = TRUE;
  575.  
  576.   if((SoundBufferReady == TRUE) || (FileReady == TRUE)) 
  577.   {
  578.     RepaintWaveCanvas();
  579.     RepaintGlobalWaveCanvas();
  580.     UpdateMessageDisplay();
  581.     currentSelectionReadyToPlay = TRUE;
  582.   }
  583.   else
  584.   {
  585.     ClearAllSound();
  586.   }
  587. }                                    /* end function SetCurrentSelection */
  588.  
  589.  
  590. void
  591.   AddSelection()
  592. {
  593.   int        i;
  594.   double    duration;
  595.   char        proposedPath[80];
  596.   char          *soundFileTextField;
  597.   
  598.   i = EditList.numItems;
  599.   
  600.   if (EditList.numItems % DEFAULT_EDITLIST_SIZE == DEFAULT_EDITLIST_SIZE - 2)
  601.     ReallocateMemoryForEditList();
  602.   
  603.   DeselectList();
  604.   soundFileTextField = (char *) xv_get(dtr_editListPanelPopUp->soundFileTextField,
  605.                        PANEL_VALUE);
  606.   
  607.   if (!NullFileName(soundFileTextField) || soundFileTextField == NULL)
  608.   {
  609.     realpath(soundFileTextField, proposedPath);
  610.     strcpy(EditList.soundFile[i], proposedPath);
  611.   
  612.     if (strcmp((char*)xv_get(dtr_editListPanelPopUp->soundFileTextField, /*  If the current string in the soundfiletextfield */
  613.                  PANEL_VALUE),                /*  ...does not represent the realpath, we set...   */
  614.            proposedPath) != 0)                    /*  ...the text field value to be the realpath.     */
  615.     {
  616.       xv_set(dtr_editListPanelPopUp->soundFileTextField,
  617.          PANEL_VALUE, proposedPath, NULL);
  618.     }
  619.   }
  620.   else
  621.   {
  622.     strcpy(EditList.soundFile[i], "");
  623.   }
  624.   
  625.   strcpy(EditList.label[i], (char*)xv_get(dtr_editListPanelPopUp->labelTextField,
  626.                       PANEL_VALUE));
  627.   EditList.startingMin[i] = atoi(xv_get(dtr_editListPanelPopUp->startingTimeMinuteTextField,
  628.                     PANEL_VALUE));
  629.   EditList.startingSec[i] = atof(xv_get(dtr_editListPanelPopUp->startingTimeSecondTextField,
  630.                     PANEL_VALUE));
  631.   EditList.endingMin[i] = atoi(xv_get(dtr_editListPanelPopUp->endingTimeMinuteTextField,
  632.                       PANEL_VALUE));
  633.   EditList.endingSec[i] = atof(xv_get(dtr_editListPanelPopUp->endingTimeSecondTextField,
  634.                       PANEL_VALUE));
  635.   EditList.volume[i] =
  636.     (int) xv_get(dtr_editListPanelPopUp->editListVolumeSlider,
  637.          PANEL_VALUE);
  638.   EditList.numItems++;
  639.   currentSelection = i;
  640.   duration = (EditList.endingMin[i] - EditList.startingMin[i]) * 60.0 
  641.     + EditList.endingSec[i] - EditList.startingSec[i];
  642.   xv_set(dtr_editListPanelPopUp->editListScrollList,
  643.      PANEL_LIST_INSERT, i,
  644.      PANEL_LIST_STRING, i,
  645.      FormatEntry(i+1, EditList.label[i], EditList.soundFile[i], duration),
  646.      PANEL_LIST_FONT, i, listFont,
  647.      NULL);
  648.   sprintf(msg, "%d", i+1);
  649.   xv_set(dtr_editListPanelPopUp->currentEditMessage,
  650.      PANEL_LABEL_STRING, msg, NULL);
  651.   UpdateNumEditsMessage();
  652.   unsavedChangesExist = TRUE;
  653.   UpdateEditListHeader(TRUE);
  654.   xv_set(dtr_editListPanelPopUp->deleteButton,                /*  Re-activate the buttons again.                  */
  655.      PANEL_INACTIVE, FALSE, NULL);
  656.   xv_set(dtr_editListPanelPopUp->modifyButton,
  657.      PANEL_INACTIVE, FALSE, NULL);
  658.   xv_set(dtr_editListPanelPopUp->editListScrollList,
  659.      PANEL_LIST_SELECT, i, TRUE, NULL);
  660. }                                    /* end function AddSelection */
  661.  
  662.  
  663. void
  664.   ModifySelection()
  665. {
  666.   double    duration;
  667.   char        proposedPath[80];
  668.   char          *soundFileTextField;
  669.   
  670.   if (currentSelection == NO_CURRENT_EDIT)
  671.   {
  672.     notice_prompt (dtr_editListPanelPopUp->editListUpperControlPanel, NULL,
  673.            NOTICE_MESSAGE_STRINGS,
  674.            "You need to select an edit before you can modify it.",
  675.            NULL,
  676.            NOTICE_BUTTON,    "OK", 100,
  677.            NULL);
  678.     return;                            
  679.   }    
  680.   soundFileTextField = (char *) xv_get(dtr_editListPanelPopUp->soundFileTextField,
  681.                        PANEL_VALUE);
  682.   
  683.   if (!NullFileName(soundFileTextField) || soundFileTextField == NULL)
  684.   {
  685.     realpath(soundFileTextField, proposedPath);
  686.     strcpy(EditList.soundFile[currentSelection], proposedPath);
  687.   
  688.     if (strcmp((char*)xv_get(dtr_editListPanelPopUp->soundFileTextField, /*  If the current string in the soundfiletextfield */
  689.                  PANEL_VALUE),                /*  ...does not represent the realpath, we set...   */
  690.            proposedPath) != 0)                    /*  ...the text field value to be the realpath.     */
  691.     {
  692.       xv_set(dtr_editListPanelPopUp->soundFileTextField,
  693.          PANEL_VALUE, proposedPath, NULL);
  694.     }
  695.   }
  696.   else
  697.   {
  698.     strcpy(EditList.soundFile[currentSelection], "");
  699.   }
  700.   strcpy(EditList.label[currentSelection],
  701.      (char*)xv_get(dtr_editListPanelPopUp->labelTextField,
  702.         PANEL_VALUE));
  703.   EditList.startingMin[currentSelection] =
  704.     atoi(xv_get(dtr_editListPanelPopUp->startingTimeMinuteTextField,
  705.         PANEL_VALUE));
  706.   EditList.startingSec[currentSelection] =
  707.     atof(xv_get(dtr_editListPanelPopUp->startingTimeSecondTextField,
  708.         PANEL_VALUE));
  709.   EditList.endingMin[currentSelection] =
  710.     atoi(xv_get(dtr_editListPanelPopUp->endingTimeMinuteTextField,
  711.         PANEL_VALUE));
  712.   EditList.endingSec[currentSelection] =
  713.     atof(xv_get(dtr_editListPanelPopUp->endingTimeSecondTextField,
  714.         PANEL_VALUE));
  715.   EditList.volume[currentSelection] =
  716.     xv_get(dtr_editListPanelPopUp->editListVolumeSlider,
  717.        PANEL_VALUE);
  718.   duration = (EditList.endingMin[currentSelection] -
  719.           EditList.startingMin[currentSelection]) * 60.0 
  720.         + EditList.endingSec[currentSelection]
  721.           - EditList.startingSec[currentSelection];
  722.   xv_set(dtr_editListPanelPopUp->editListScrollList,
  723.      PANEL_LIST_STRING, currentSelection,
  724.      FormatEntry(currentSelection+1, EditList.label[currentSelection],
  725.              EditList.soundFile[currentSelection],
  726.              duration),
  727.      PANEL_LIST_FONT, currentSelection, listFont,
  728.      NULL);
  729.   xv_set(dtr_editListPanelPopUp->deleteButton,                /*  Re-activate the buttons again.                  */
  730.      PANEL_INACTIVE, FALSE, NULL);
  731.   xv_set(dtr_editListPanelPopUp->modifyButton,
  732.      PANEL_INACTIVE, FALSE, NULL);
  733.   UpdateNumEditsMessage();
  734.   unsavedChangesExist = TRUE;
  735.   UpdateEditListHeader(TRUE);
  736. }                                    /* end function ModifySelection */
  737.  
  738.  
  739. void
  740.   DeleteSelection()
  741.   int    savedCurrentSelection;
  742.   
  743.   if (currentSelection == NO_CURRENT_EDIT)
  744.   {
  745.     notice_prompt (dtr_editListPanelPopUp->editListUpperControlPanel, NULL,
  746.            NOTICE_MESSAGE_STRINGS,
  747.            "You need to select an edit before you can delete it.",
  748.            NULL,
  749.            NOTICE_BUTTON,    "OK", 100,
  750.            NULL);
  751.     return;                            
  752.   }    
  753.   savedCurrentSelection = currentSelection;
  754.   
  755.   DeselectList();
  756. /******************
  757.   if (savedCurrentSelection != 0)
  758.   {
  759.     xv_set(dtr_editListPanelPopUp->editListScrollList,
  760.        PANEL_LIST_SELECT, savedCurrentSelection - 1, TRUE,
  761.        NULL);
  762.   }
  763. ********************/  
  764.   xv_set(dtr_editListPanelPopUp->editListScrollList,
  765.      PANEL_LIST_DELETE, savedCurrentSelection,
  766.      NULL);
  767.   DeleteItemFromEditList(savedCurrentSelection);
  768. /**************
  769.   if (savedCurrentSelection != 0)
  770.   {
  771.     xv_set(dtr_editListPanelPopUp->editListScrollList,
  772.        PANEL_LIST_SELECT, savedCurrentSelection - 1, FALSE,
  773.        NULL);
  774.   }
  775. ***************/
  776.   UpdateNumEditsMessage();
  777.   unsavedChangesExist = TRUE;
  778.   UpdateEditListHeader(TRUE);
  779.   xv_set(dtr_editListPanelPopUp->deleteButton,
  780.      PANEL_INACTIVE, TRUE, NULL);
  781.   xv_set(dtr_editListPanelPopUp->modifyButton,
  782.      PANEL_INACTIVE, TRUE, NULL);
  783. }                                    /* end function DeleteSelection */
  784.  
  785.   
  786. void
  787.   DeleteItemFromEditList(itemNumber)
  788. int    itemNumber;
  789. {
  790.   int        i;
  791.  
  792.   if (itemNumber+1 == EditList.numItems)                /*  If the last item is going to be deleted...      */
  793.   {                                    /*  ... then we dont have to shuffle any items up.. */
  794.     EditList.numItems--;                        /*  ... in the list.                                */
  795.     RedrawEditList(itemNumber);                        /*  Update number of items in the edit list.        */
  796.     return;
  797.   }
  798.   for (i = itemNumber; i < EditList.numItems; i++)
  799.   {
  800.     strcpy(EditList.soundFile[i], EditList.soundFile[i+1]);
  801.     strcpy(EditList.label[i], EditList.label[i+1]);
  802.     EditList.startingMin[i] = EditList.startingMin[i+1];
  803.     EditList.startingSec[i] = EditList.startingSec[i+1];
  804.     EditList.endingMin[i] = EditList.endingMin[i+1];
  805.     EditList.endingSec[i] = EditList.endingSec[i+1];
  806.     EditList.volume[i] = EditList.volume[i+1];
  807.   }
  808.   EditList.numItems--;
  809.   RedrawEditList(itemNumber);
  810.   return;
  811. }                                    /* end function DeleteItemFromEditList */
  812.  
  813.  
  814. void
  815.   RedrawEditList(entryNum)
  816. int   entryNum;
  817. {
  818.   int        i;
  819.   double    duration;
  820.  
  821.   for(i = entryNum; i < EditList.numItems ; i++)
  822.   {
  823.     duration = (EditList.endingMin[i] -
  824.         EditList.startingMin[i]) * 60.0 
  825.           + EditList.endingSec[i]
  826.             - EditList.startingSec[i];
  827.     
  828.     xv_set(dtr_editListPanelPopUp->editListScrollList,
  829.        PANEL_LIST_STRING, i, FormatEntry(i+1,
  830.                          EditList.label[i],
  831.                          EditList.soundFile[i],
  832.                          duration),
  833.        PANEL_LIST_FONT, i, listFont,
  834.        NULL);
  835.   }
  836.  
  837.   return;
  838. }                                    /* end function RedrawEditList */
  839.  
  840.        
  841. void
  842.   DeleteAllSelections()
  843. {
  844.   DeselectList();
  845.   ResetCurrentSelection();
  846.   EmptyList();
  847.   UpdateNumEditsMessage();
  848.   unsavedChangesExist = TRUE;
  849.   xv_set(dtr_editListPanelPopUp->deleteButton,                /*  De-activate the Delete and Modify buttons.      */
  850.      PANEL_INACTIVE, TRUE, NULL);
  851.   xv_set(dtr_editListPanelPopUp->modifyButton,
  852.      PANEL_INACTIVE, TRUE, NULL);
  853. }                                    /* end function DeleteAllSelections */
  854.  
  855.  
  856. void
  857.   NewEditList()
  858. {
  859.   DeleteAllSelections();
  860.   sprintf(absoluteEditListName, "Untitled");
  861.   UpdateEditListHeader(FALSE);
  862. }
  863.  
  864.   
  865. void
  866.   DisableEditListPanel()
  867. {
  868.   extern  dtr_editListPanelPopUp_objects *dtr_editListPanelPopUp;
  869.  
  870.   xv_set(dtr_editListPanelPopUp->addButton,                
  871.      PANEL_INACTIVE, TRUE, NULL);
  872.   xv_set(dtr_editListPanelPopUp->modifyButton,
  873.      PANEL_INACTIVE, TRUE, NULL);
  874.   xv_set(dtr_editListPanelPopUp->deleteButton,                
  875.      PANEL_INACTIVE, TRUE, NULL);
  876.   xv_set(dtr_editListPanelPopUp->deleteAllButton,
  877.      PANEL_INACTIVE, TRUE, NULL);
  878.   
  879.   xv_set(dtr_editListPanelPopUp->editListScrollList,
  880.      PANEL_INACTIVE, TRUE, NULL);
  881. }
  882.  
  883.  
  884.   
  885. void
  886.   EnableEditListPanel()
  887. {
  888.   extern  dtr_editListPanelPopUp_objects *dtr_editListPanelPopUp;
  889.  
  890.   xv_set(dtr_editListPanelPopUp->addButton,
  891.      PANEL_INACTIVE, FALSE, NULL);
  892.   xv_set(dtr_editListPanelPopUp->modifyButton,
  893.      PANEL_INACTIVE, FALSE, NULL);
  894.   xv_set(dtr_editListPanelPopUp->deleteButton,                
  895.      PANEL_INACTIVE, FALSE, NULL);
  896.   xv_set(dtr_editListPanelPopUp->deleteAllButton,
  897.      PANEL_INACTIVE, FALSE, NULL);
  898.   
  899.   xv_set(dtr_editListPanelPopUp->editListScrollList,
  900.      PANEL_INACTIVE, FALSE, NULL);
  901. }
  902.